home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / asm / adisv1_3.lha / src / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-14  |  15.2 KB  |  477 lines

  1. /*
  2.  * Change history
  3.  * $Log:    defs.h,v $
  4.  * Revision 3.0  93/09/24  17:54:36  Martin_Apel
  5.  * New feature: Added extra 68040 FPU opcodes
  6.  * 
  7.  * Revision 2.4  93/07/18  22:57:05  Martin_Apel
  8.  * *** empty log message ***
  9.  * 
  10.  * Revision 2.3  93/07/11  21:40:10  Martin_Apel
  11.  * Major mod.: Jump table support tested and changed
  12.  * 
  13.  * Revision 2.2  93/07/10  13:02:39  Martin_Apel
  14.  * Major mod.: Added full jump table support. Seems to work quite well
  15.  * 
  16.  * Revision 2.1  93/07/08  20:50:47  Martin_Apel
  17.  * Minor mod.: Added print_flags for debugging purposes
  18.  * 
  19.  * Revision 2.0  93/07/01  11:55:04  Martin_Apel
  20.  * *** empty log message ***
  21.  * 
  22.  * Revision 1.30  93/07/01  11:46:54  Martin_Apel
  23.  * Minor mod.: Prepared for tabs instead of spaces
  24.  * 
  25.  * Revision 1.29  93/06/19  12:12:20  Martin_Apel
  26.  * Major mod.: Added full 68030/040 support
  27.  * 
  28.  * Revision 1.28  93/06/16  20:31:52  Martin_Apel
  29.  * Minor mod.: Removed #ifdef FPU_VERSION and #ifdef MACHINE68020
  30.  * Minor mod.: Added variables for 68030 / 040 support
  31.  * 
  32.  * Revision 1.27  93/06/06  13:48:45  Martin_Apel
  33.  * Minor mod.: Added preliminary support for jump tables recognition
  34.  * Minor mod.: Replaced first_pass and read_symbols by pass1, pass2, pass3
  35.  * 
  36.  * Revision 1.26  93/06/06  00:16:26  Martin_Apel
  37.  * Major mod.: Added support for library/device disassembly (option -dl)
  38.  * 
  39.  * Revision 1.25  93/06/04  11:57:34  Martin_Apel
  40.  * New feature: Added -ln option for generation of ascending label numbers
  41.  * 
  42.  * Revision 1.24  93/06/03  20:31:01  Martin_Apel
  43.  * New feature: Added -a switch to generate comments for file offsets
  44.  * 
  45.  * Revision 1.23  93/06/03  18:28:15  Martin_Apel
  46.  * Minor mod.: Added new prototypes an variables for hunk-handling routines.
  47.  * Minor mod.: Remove temporary files upon exit (even with CTRL-C).
  48.  * 
  49.  */
  50.  
  51. #include <exec/types.h>
  52. #include <stdio.h>
  53. #ifdef MCH_AMIGA
  54. #ifndef AMIGA
  55. #define AMIGA
  56. #endif
  57. #endif
  58.  
  59. /* $Id: defs.h,v 3.0 93/09/24 17:54:36 Martin_Apel Exp $ */
  60.  
  61. struct opcode_entry
  62.   {
  63.   int (*handler) (struct opcode_entry*);
  64.                                   
  65.   char *mnemonic;
  66.   unsigned short param;           /* given to handler () */
  67.   unsigned char modes;            /* addressing modes allowed for this 
  68.                                      opcode */
  69.   unsigned char submodes;         /* addressing submodes of mode 7 allowed
  70.                                      for this opcode */
  71.   unsigned short chain;           /* if another opcode is possible for */
  72.                                   /* this bit pattern, this is the index */
  73.                                   /* of another entry in opcode_table. */
  74.                                   /* Otherwise it's zero */
  75.   };
  76.  
  77. #define TRANSFER 0                /* The handler didn't handle this opcode */
  78.                                   /* Transfer to next in chain */
  79.  
  80. /* Param values */
  81. /* General */
  82. #define MEM 9
  83. #define REG 10
  84. /* Bitfield instructions */
  85. #define DATADEST 0
  86. #define DATASRC  1
  87. #define SINGLEOP 2
  88. /* MOVE to or from SR, CCR */
  89. #define TO_CCR   0
  90. #define FROM_CCR 1
  91. #define TO_SR    2
  92. #define FROM_SR  3
  93. /* Extended precision and BCD instructions */
  94. #define NO_ADJ 0
  95. #define ADJUST 1
  96.  
  97.  
  98. /* Bit masks */
  99. #define EA_MODE 0x038      /* Bits 5 - 3 */
  100. #define EA_REG  0x007      /* Bits 2 - 0 */
  101. #define REG2    0xe00      /* Bits 11 - 9 */
  102. #define OP_MODE 0x1c0      /* Bits 8 - 6 */
  103.  
  104. /* Shift values */
  105. #define MODE_SHIFT 3
  106. #define REG2_SHIFT 9
  107. #define OP_MODE_SHIFT 6
  108.  
  109. #define MODE_NUM(x) ((short)(((x) >> 3) & 0x7))
  110. #define REG_NUM(x)  ((short)((x) & EA_REG))
  111.  
  112. #define USE_SIGN    TRUE
  113. #define NO_SIGN     FALSE
  114. #define USE_LABEL   TRUE
  115. #define NO_LABEL    FALSE
  116. #define USE_COMMENT TRUE
  117. #define NO_COMMENT  FALSE
  118.  
  119. #define DEF_BUF_SIZE (10L * 1024L)
  120.  
  121. enum 
  122.   {
  123.   SR, CCR, USP, SFC, DFC, CACR, VBR, CAAR, MSP, ISP, TC, 
  124.   ITT0, ITT1, DTT0, DTT1, MMUSR, URP, SRP, TT0, TT1, CRP
  125.   };
  126.  
  127. /* Access types for reference table. */
  128. #define NO_ACCESS   (UWORD)0x00     /* not referenced yet */
  129. #define ACC_BYTE    (UWORD)0x01     /* referenced as bytewide data */
  130. #define ACC_WORD    (UWORD)0x02
  131. #define ACC_LONG    (UWORD)0x04
  132. #define ACC_DOUBLE  (UWORD)0x08
  133. #define ACC_EXTEND  (UWORD)0x10
  134. #define ACC_CODE    (UWORD)0x20     /* referenced as code */
  135. #define ACC_DATA    (UWORD)0x40     /* referenced as data, but size unknown */
  136. #define ACC_UNKNOWN (UWORD)0x80     /* accessed but it's unknown, if it's code */
  137.                                     /* or data */
  138.  
  139. #define OPCODE_COL 20               /* at which column opcode and params are */
  140. #define PARAM_COL 35                /* placed */
  141. #define COMMENT_COL 60
  142.  
  143. #define PC (short)16                /* index into reg_names array */
  144.  
  145.  
  146. #define TMP_CODE               0x01
  147. #define TMP_DATA               0x02
  148. #define TMP_STRING             0x04
  149. #define PERM_CODE              0x08
  150. #define PERM_DATA              0x10
  151. #define PERM_STRING            0x20
  152. #define PERM_RELOC             0x40
  153. #define NEW                    0x80
  154.  
  155. #define PERM_MASK              (PERM_CODE|PERM_DATA|PERM_STRING)
  156. #define TMP_MASK               (TMP_CODE|TMP_DATA|TMP_STRING)
  157. #define PERM2TMP               3       /* Shift value to restore old settings */
  158.                                        /* for TMP bits */
  159. #define TMP2PERM               3       /* Shift value to save settings */
  160.                                        /* settings for PERM bits */
  161.  
  162. /* Restore old settings of flag bits */
  163. #define RESTORE(x)             {\
  164.                                (x) = ((x) & (PERM_MASK | PERM_RELOC)) |\
  165.                                      (((x) & PERM_MASK) >> PERM2TMP);\
  166.                                }
  167.  
  168. #define SAVE(x)                {\
  169.                                (x) |= ((x) & TMP_MASK) << TMP2PERM;\
  170.                                (x) &= ~NEW;\
  171.                                }
  172.  
  173. #define SAVE_LONG(x)           {\
  174.                                (x) |= ((x) & (TMP_MASK | (TMP_MASK << 8) |\
  175.                                       (TMP_MASK << 16) | (TMP_MASK << 24)))\
  176.                                       << TMP2PERM;\
  177.                                (x) &= ~(NEW | (NEW << 8) | (NEW << 16) | (NEW << 24));\
  178.                                }
  179.  
  180. #define IS_RELOCATED(address)  (*(flags + (address) - first_address) & PERM_RELOC)
  181. #define IS_CODE(address)       (*(flags + (address) - first_address) & TMP_CODE)
  182. #define IS_DATA(address)       (*(flags + (address) - first_address) & TMP_DATA)
  183. #define IS_STRING(address)     (*(flags + (address) - first_address) & TMP_STRING)
  184. #define IS_SURE(address)       (*(flags + (address) - first_address) &\
  185.                                         (TMP_CODE | TMP_DATA))
  186. #define IS_PROBABLE(address)   (*(flags + (address) - first_address) &\
  187.                                         (TMP_CODE | TMP_DATA | TMP_STRING))
  188. #define IS_NEW(address)        (*(flags + (address) - first_address) & NEW)
  189.  
  190. #define IS_RELOCATED_P(ptr)  (*(ptr) & PERM_RELOC)
  191. #define IS_CODE_P(ptr)       (*(ptr) & TMP_CODE)
  192. #define IS_DATA_P(ptr)       (*(ptr) & TMP_DATA)
  193. #define IS_STRING_P(ptr)     (*(ptr) & TMP_STRING)
  194. #define IS_SURE_P(ptr)       (*(ptr) & (TMP_CODE | TMP_DATA))
  195. #define IS_PROBABLE_P(ptr)   (*(ptr) & (TMP_CODE | TMP_DATA | TMP_STRING))
  196. #define IS_NEW_P(address)    (*(ptr) & NEW)
  197.  
  198. #define TMP_FILENAME "t:ADis68k"
  199.  
  200. /* Marker for jump-tables */
  201. #define UNSET 0xffffffffL
  202.  
  203. #define ODD(x) ((x) & 1)
  204. #define EVEN(x) (!ODD(x))
  205.  
  206. extern unsigned short *code;
  207. extern char opcode [];
  208. extern char src [];
  209. extern char dest [];
  210. extern char instruction [];
  211. extern struct opcode_entry opcode_table [];
  212. extern struct opcode_entry mmu_opcode_table [];
  213. extern unsigned long current_address;
  214. extern unsigned long first_address;     /* start address of current hunk */
  215. extern unsigned long last_address;      /* last address of current hunk */
  216. extern unsigned long current_hunk;
  217. extern unsigned long total_size;
  218. extern unsigned char *flags;
  219. extern BOOL end_instr;
  220. extern BOOL verbose;
  221. extern char *reg_names []; 
  222. extern char *special_regs [];
  223. extern char *conditions [];
  224. extern FILE *in,
  225.             *out,
  226.             *tmp_f;
  227. extern char *in_buf,
  228.             *out_buf;
  229. extern char *input_filename;
  230. extern char output_filename[];
  231. extern int buf_size;
  232. extern BOOL try_small;
  233. extern long a4_offset;
  234. extern long *hunk_start,
  235.             *hunk_end,
  236.             *hunk_offset;
  237. extern BOOL pass1,
  238.             pass2,
  239.             pass3;
  240. extern BOOL detected_illegal;
  241. extern BOOL mc68020,
  242.             mc68881,
  243.             ext_68020_modes,
  244.             mc68030,
  245.             mc68040;
  246. extern BOOL disasm_quick;
  247. extern BOOL print_illegal_instr_address;
  248. extern BOOL warning_printed;
  249. extern BOOL user_wants_single_file,
  250.             user_wants_separate_files;
  251. extern BOOL add_file_offset;
  252. extern BOOL single_file;
  253. extern int num_code_hunks;
  254. extern int num_data_hunks;
  255. extern int num_bss_hunks;
  256. extern int num_hunks;
  257. extern long f_offset;
  258. /* pointer to format_line function: */
  259. extern void (*format_line) (BOOL, BOOL);
  260.  
  261. extern BOOL ascending_label_numbers;
  262. #ifdef AMIGA
  263. extern BOOL disasm_as_lib;
  264. extern BOOL ROMTagFound;
  265. #endif
  266. extern short mc68020_disabled [];
  267. extern short mc68030_disabled [];
  268. extern short mc68040_disabled [];
  269. extern short mc68881_disabled [];
  270. extern BOOL use_tabs;
  271. extern short tabsize;
  272.  
  273. /* Prototypes */
  274.  
  275. /* analyze.c */
  276. void save_flags(void);
  277. void restore_flags(void);
  278. #ifdef DEBUG
  279. void get_first_code_label(void);
  280. void examine_direct_refs(unsigned short *seg, unsigned long seg_size);
  281. short examine_unknown_labels(unsigned short *seg, unsigned long seg_size);
  282. short guess(unsigned short *seg, unsigned long seg_size);
  283. void last_touch(unsigned short *seg, unsigned long seg_size);
  284. #endif
  285. void disasm_code_1st(unsigned short *seg, unsigned long seg_size);
  286. #ifdef DEBUG
  287. void print_flags (ULONG from);
  288. #endif
  289.  
  290. /* decode_ea.c */
  291. int decode_ea (short mode, short reg, char *where_to, short access, 
  292.                short first_ext);
  293.  
  294. /* disasm_code.c */
  295. short disasm_instr (void);
  296. void disasm_code (USHORT *seg, ULONG seg_size);
  297. void disasm_code_1st (USHORT *seg, ULONG seg_size);
  298.  
  299. /* disasm_data.c */
  300. void disasm_data (UBYTE *data_seg, ULONG seg_size);
  301. void disasm_bss (void);
  302.  
  303. /* main.c */
  304. void main (int argc, char *argv []);
  305. void parse_args (int argc, char *argv []);
  306. #ifdef DEBUG
  307. void Usage (void);
  308. #endif
  309. void open_files (void);
  310. void close_files (void);
  311. void open_output_file (void);
  312. void close_output_file (void);
  313. void ExitADis (void);
  314. #ifdef AZTEC_C
  315. void _abort (void);
  316. #endif
  317. #ifdef DEBUG
  318. void check_consistency (void);
  319. #endif
  320.  
  321. /* util.c */
  322. char *format_d (char *where, short val, BOOL sign);
  323. char *format_ld  (char *where, long val, BOOL sign);
  324. char *format_ld_no_dollars  (char *where, long val, BOOL sign);
  325. void format_reg_list (char *where, unsigned short list, BOOL to_mem, 
  326.                       short reglist_offset);
  327. char *immed (char *to, long val);
  328. void pre_dec (char *to, short reg_num);
  329. void post_inc (char *to, short reg_num);
  330. void indirect (char *to, short reg_num);
  331. void disp_an (char *to, short reg_num, short disp);
  332. void disp_an_indexed (char *to, short an, char disp, short index_reg, 
  333.                       short scale, short size);
  334. int full_extension (char *to, unsigned short *extension, short mode, short reg);
  335. void format_line_spaces (BOOL labeled, BOOL commented);
  336. int gen_label (char *where_to, ULONG ref, BOOL anyway);
  337. BOOL is_string (char *maybe_string, ULONG max_len);
  338. void put (char *string);
  339. char *cpstr (char *dest, char *src, int max_len);
  340. void gen_xref (ULONG address);
  341. void assign_label_names (void);
  342.  
  343. void mark_entry_illegal (int entry);
  344.  
  345. /* hunks.c */
  346. long getlong(void);
  347. unsigned short getword(void);
  348. BOOL readfile(void);
  349. BOOL read_hunk_header(void);
  350. BOOL read_hunk_overlay(void);
  351. BOOL read_code_hunk(void);
  352. BOOL read_data_hunk(void);
  353. BOOL read_bss_hunk(void);
  354. BOOL read_symbol_hunk(void);
  355. BOOL read_reloc32_hunk(USHORT *hunk_start);
  356. BOOL read_reloc16_hunk(USHORT *hunk_start);
  357.  
  358.  
  359. /* ref_table.c */
  360. BOOL init_ref_table (ULONG size);
  361. void kill_ref_table (void);
  362. void enter_ref (ULONG offset, char *name, UWORD access_type);
  363. ULONG ext_enter_ref (ULONG offset, ULONG hunk, char *name, UWORD access_type);
  364. BOOL find_reference (ULONG offset, char **name, UWORD *access_type);
  365. BOOL find_active_reference (ULONG offset, char **name, UWORD *access_type);
  366. ULONG next_reference (ULONG from, ULONG to, UWORD *access);
  367. ULONG next_active_reference (ULONG from, ULONG to, UWORD *access);
  368. void deactivate_labels (ULONG from, ULONG to);
  369. void make_labels_permanent (void);
  370. void delete_tmp_labels (void);
  371.  
  372. /* mem.c */
  373. void *get_mem(unsigned long size);
  374. void release_mem(void *buffer);
  375.  
  376. /* user_defined.c */
  377. void predefine_label(unsigned long address, unsigned short access);
  378. void add_predefined_labels(void);
  379.  
  380. #ifdef DEBUG
  381. void print_ref_table (ULONG from, ULONG to);
  382. void print_active_table (ULONG from, ULONG to);
  383. void check_active_table (void);
  384. #endif
  385.  
  386. #ifdef DEBUG
  387. #define PRIVATE
  388. #else
  389. #define PRIVATE static
  390. #endif
  391.  
  392. /* opcode_handler.c */
  393. int bit_reg (struct opcode_entry *op);
  394. int bit_mem (struct opcode_entry *op);
  395. int move    (struct opcode_entry *op);
  396. int movem   (struct opcode_entry *op);
  397. int moveq   (struct opcode_entry *op);
  398. int srccr   (struct opcode_entry *op);
  399. int special (struct opcode_entry *op);
  400. int off_illegal (struct opcode_entry *op);
  401. int illegal (struct opcode_entry *op);
  402. int immediate (struct opcode_entry *op);
  403. int ori_b   (struct opcode_entry *op);
  404. int single_op (struct opcode_entry *op);
  405. int end_single_op (struct opcode_entry *op);
  406. int dual_op (struct opcode_entry *op);
  407. int quick   (struct opcode_entry *op);
  408. int branch  (struct opcode_entry *op);
  409. int dbranch (struct opcode_entry *op);
  410. int shiftreg(struct opcode_entry *op);
  411. int op_w    (struct opcode_entry *op);
  412. int op_l    (struct opcode_entry *op);
  413. int restrict(struct opcode_entry *op);
  414. int scc     (struct opcode_entry *op);
  415. int exg     (struct opcode_entry *op);
  416. int movesrccr (struct opcode_entry *op);
  417. int cmpm    (struct opcode_entry *op);
  418. int movep   (struct opcode_entry *op);
  419. int bkpt    (struct opcode_entry *op);
  420. int muldivl (struct opcode_entry *op);
  421. int bf_op   (struct opcode_entry *op);
  422. int trapcc  (struct opcode_entry *op);
  423. int chkcmp2 (struct opcode_entry *op);
  424. int cas     (struct opcode_entry *op);
  425. int cas2    (struct opcode_entry *op);
  426. int moves   (struct opcode_entry *op);
  427. int link_l  (struct opcode_entry *op);
  428. int move16  (struct opcode_entry *op);
  429. int cache   (struct opcode_entry *op);
  430.  
  431. #define SNG_ALL 1        /* Single operand syntax allowed */
  432.  
  433. /* fpu_opcodes.c */
  434. extern struct opcode_entry fpu_opcode_table [];
  435. extern char *xfer_size [];
  436. extern short sizes [];
  437. extern char *fpu_conditions [];
  438.  
  439. /* opcode_handler_fpu.c */
  440. int fpu (struct opcode_entry *op);
  441. int std_fpu (struct opcode_entry *op);
  442. int fsincos (struct opcode_entry *op);
  443. int fscc (struct opcode_entry *op);
  444. int fbranch (struct opcode_entry *op);
  445. int fdbranch (struct opcode_entry *op);
  446. int ftrapcc (struct opcode_entry *op);
  447.  
  448. /* opcode_handler_mmu.c */
  449. int pflush40(struct opcode_entry *op);
  450. int ptest40(struct opcode_entry *op);
  451. int mmu30(struct opcode_entry *op);
  452. int ptest30(struct opcode_entry *op);
  453. int pfl_or_ld(struct opcode_entry *op);
  454. int pflush30(struct opcode_entry *op);
  455. int pmove30(struct opcode_entry *op);
  456.  
  457. /* amiga.c */
  458. BOOL user_aborted_analysis (void);
  459. void delete_tmp_files (void);
  460. #ifdef AMIGA
  461. BOOL add_lib_labels (UWORD *seg);
  462. #endif
  463.  
  464. /* version.c */
  465. void print_version (void);
  466.  
  467. /* jmptab.c */
  468. void free_jmptab_list (void);
  469. void enter_jmptab (ULONG start, ULONG offset);
  470. BOOL next_code_ref_from_jmptab (UWORD *seg);
  471. BOOL invalidate_last_jmptab_entry (void);
  472. BOOL find_jmptab_and_print (char *string);
  473.  
  474. #ifdef DEBUG
  475. void print_jmptab_list (void);
  476. #endif
  477.